package com.edu.exam.entity.grading.integration;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;

/**
 * 数据转换规则实体类
 *
 * <p>所属模块：B-06 成绩管理模块</p>
 * <p>对应数据库表：data_transform_rule</p>
 *
 * <p>存储数据转换规则配置</p>
 *
 * @author G-09 Module Designer
 * @version 2.0
 * @since 2025-11-10
 */
@Entity
@Data
@EqualsAndHashCode(callSuper = false)
public class DataTransformRule {

    @Id
    @Column(name = "rule_id", length = 64)
    private String ruleId;

    @Column(name = "rule_name", length = 128, nullable = false)
    private String ruleName;

    @Column(name = "source_system", length = 32, nullable = false)
    private String sourceSystem;

    @Column(name = "source_format", length = 32, nullable = false)
    private String sourceFormat;

    @Column(name = "target_format", length = 32, nullable = false)
    private String targetFormat;

    @Column(name = "transform_type", length = 32, nullable = false)
    private String transformType;

    @Column(name = "transform_config", columnDefinition = "TEXT")
    private String transformConfig;

    @Column(name = "mapping_rules", columnDefinition = "TEXT")
    private String mappingRules;

    @Column(name = "validation_rules", columnDefinition = "TEXT")
    private String validationRules;

    @Column(name = "status", length = 32, nullable = false)
    private String status;

    @Column(name = "priority", nullable = false)
    private Integer priority = 5;

    @Column(name = "created_by", length = 64)
    private String createdBy;

    @CreationTimestamp
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    @Column(name = "updated_by", length = 64)
    private String updatedBy;

    @UpdateTimestamp
    @Column(name = "updated_time")
    private LocalDateTime updatedTime;

    @Version
    @Column(name = "version", nullable = false)
    private Integer version = 1;

    @PrePersist
    protected void onCreate() {
        if (status == null) {
            status = "active";
        }
        if (priority == null) {
            priority = 5;
        }
        if (version == null) {
            version = 1;
        }
    }
}